package br.com.wuo.karina.view;

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;

/**
 * 
 * @author Renan Wuo
 */
public class View extends JFrame {

	private static final long serialVersionUID = 1L;

	private JMenuItem itemSalvarAluno, itemPesquisarAluno, itemSalvarAula,
			itemPesquisarAula, itemSalvarProfessor, itemPesquisarProfessor,
			itemPagamentoProfessor, /*itemMensalidades,*/
			itemSalvarTurma, itemAtribuirTurma, itemSair;
	private JScrollPane scrollPane;
	private JPanel topPanel;

	public View() {
		super("Controle de Alunos");

		topPanel = new JPanel();
		topPanel.setLayout(new BorderLayout());

		scrollPane = new JScrollPane();

		initialize();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(800, 600);
		setExtendedState(JFrame.MAXIMIZED_BOTH);
		// view = this;
		addListener();
	}

	public void initialize() {
		setLayout(new BorderLayout());

		topPanel.add(scrollPane);
		add(topPanel);

		JMenuBar menuBar = new JMenuBar();
		JMenu menuFile = new JMenu("Arquivo");
		JMenu menuAluno = new JMenu("Aluno");
		JMenu menuAula = new JMenu("Aula");
		JMenu menuProfessor = new JMenu("Professor");
		JMenu menuTurma = new JMenu("Turma");
		JMenu menuFinanceiro = new JMenu("Financeiro");
		itemSalvarAluno = new JMenuItem("Cadastrar");
		itemPesquisarAluno = new JMenuItem("Pesquisar");
		itemSalvarAula = new JMenuItem("Cadastrar");
		itemPesquisarAula = new JMenuItem("Pesquisar");
		itemSalvarProfessor = new JMenuItem("Cadastrar");
		itemPesquisarProfessor = new JMenuItem("Pesquisar");
		itemPagamentoProfessor = new JMenuItem("Pagamentos");
//		itemMensalidades = new JMenuItem("Mensalidades");
		itemSalvarTurma = new JMenuItem("Cadastrar");
		itemAtribuirTurma = new JMenuItem("Atribuir");
		itemSair = new JMenuItem("Sair");
		menuFile.add(itemSair);
		menuAluno.add(itemSalvarAluno);
		menuAluno.add(itemPesquisarAluno);
		menuAula.add(itemSalvarAula);
		menuAula.add(itemPesquisarAula);
		menuProfessor.add(itemSalvarProfessor);
		menuProfessor.add(itemPesquisarProfessor);
		menuFinanceiro.add(itemPagamentoProfessor);
//		menuFinanceiro.add(itemMensalidades);
		menuTurma.add(itemSalvarTurma);
		menuTurma.add(itemAtribuirTurma);
		menuBar.add(menuFile);
		menuFile.setMnemonic(KeyEvent.VK_A);
		itemSair.setMnemonic(KeyEvent.VK_S);
		itemSair.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
		menuBar.add(menuAluno);
		menuBar.add(menuAula);
		menuBar.add(menuProfessor);
		menuBar.add(menuTurma);
		menuBar.add(menuFinanceiro);
		setJMenuBar(menuBar);

		pack();
	}

	public void addListener() {

		itemSair.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int confirmacao = JOptionPane.showConfirmDialog(View.this,
						"Tem certeza que deseja sair?", "Confirmação",
						JOptionPane.OK_CANCEL_OPTION);
				if (confirmacao == JOptionPane.OK_OPTION) {
					System.exit(0);
				}

			}
		});

		itemSalvarAluno.addActionListener(new java.awt.event.ActionListener() {

			public void actionPerformed(java.awt.event.ActionEvent e) {
				new SalvarAluno().setVisible(true);
			}
		});

		itemPesquisarAluno.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new PesquisarAluno().setVisible(true);

			}
		});

		itemSalvarAula.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new SalvarAula().setVisible(true);

			}
		});

		itemPesquisarAula.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new PesquisarAula().setVisible(true);

			}
		});

		itemSalvarProfessor.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new SalvarProfessor().setVisible(true);

			}
		});

		itemPesquisarProfessor.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new PesquisarProfessor().setVisible(true);

			}
		});


		itemSalvarTurma.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new SalvarTurma().setVisible(true);

			}
		});
		
		itemAtribuirTurma.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new AtribuirTurma().setVisible(true);
				
			}
		});

		itemPagamentoProfessor.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new Pagamentos().setVisible(true);
			}
		});


//		itemMensalidades.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				new Mensalidades().setVisible(true);
//			}
//		});
	}
}